import {defineStore} from "pinia";
import {getUserInfo} from "@/api/login.js";

export const useLoginStore = defineStore('useLoginStore', {
    state: () => {
        return {
            userInfo: {}
        }
    }, getters: {
        getUserInfo: function () {
            return this.userInfo
        }
    }, actions: {
        setUserInfo: function (data) {
            this.userInfo = data;
        },
        fetchUserInfo: async () => {
            return new Promise(async (resolve, reject) => {
                await getUserInfo().then(res => {
                    // state.userInfo = res?.data;
                    // console.log('获取用户信息：', state.userInfo)
                    localStorage.setItem('user-info', JSON.stringify(res?.data));
                    resolve(res?.data);
                }).catch(err => {
                    console.log(err);
                    reject(err);
                });
            });
        }
    }
});